﻿package plugin.shop.component
{
    import __AS3__.vec.*;
    import cmd.*;
    import com.core.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.shop.*;
    import vo.*;

    public class NewSellPage extends Sprite
    {
        private var itemList:Vector.<NewShopItem>;
        private var tools:Array;
        private var _npcid:int = 0;
        private var toolArray:Array;
        private var chushouBtn:Button;
        private var xiuliBtn:Button;
        private var shop:Object;
        private var items:Object;

        public function NewSellPage()
        {
            this.shop = ConfigDictionary.data.shop;
            this.items = ConfigDictionary.data.item;
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this.chushouBtn = new Button();
            this.chushouBtn.skin = "png.common.btn_cs2_bag";
            this.chushouBtn.x = 137;
            this.chushouBtn.y = 375;
            this.chushouBtn.label = "出售";
            this.chushouBtn.labelColors = "0xb29a6c,0xb29a6c,0xfff7af";
            this.chushouBtn.labelStroke = "1";
            this.chushouBtn.addEventListener(MouseEvent.CLICK, this.onChuShou);
            this.xiuliBtn = new Button();
            this.xiuliBtn.skin = "png.common.btn_cs2_bag";
            this.xiuliBtn.x = 220;
            this.xiuliBtn.y = 340;
            this.xiuliBtn.label = "修理";
            this.xiuliBtn.labelColors = "0xb29a6c,0xb29a6c,0xfff7af";
            this.xiuliBtn.labelStroke = "1";
            this.xiuliBtn.addEventListener(MouseEvent.CLICK, this.onXiuLi);
            return;
        }// end function

        public function updateWorldlevel() : void
        {
            this.npcid = this._npcid;
            return;
        }// end function

        public function get npcid() : int
        {
            return this._npcid;
        }// end function

        public function set npcid(param1:int) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Object = null;
            var _loc_5:NewShopItem = null;
            var _loc_6:String = null;
            var _loc_7:String = null;
            var _loc_8:String = null;
            this._npcid = param1;
            if (this.toolArray)
            {
                this.toolArray = null;
            }
            this.toolArray = new Array();
            if (this.itemList)
            {
                _loc_2 = 0;
                while (_loc_2 < this.itemList.length)
                {
                    
                    this.itemList[_loc_2].dispose();
                    _loc_2++;
                }
                this.itemList = null;
            }
            this.itemList = new Vector.<NewShopItem>;
            _loc_2 = 0;
            while (_loc_2 < 16)
            {
                
                _loc_5 = new NewShopItem();
                _loc_5.x = 165 * int(_loc_2 % 2);
                _loc_5.y = (65 + 6) * int(_loc_2 / 2);
                ((this.parent as ShopUICtrl).panel as Panel).addChild(_loc_5);
                this.itemList.push(_loc_5);
                _loc_2++;
            }
            var _loc_4:int = 1;
            if (Config.debug && Config.sellAll)
            {
                for (_loc_6 in this.shop)
                {
                    
                    _loc_4 = this.shop[_loc_6].selltype;
                    _loc_3 = ItemObject.create(this.items[this.shop[_loc_6].itemid]);
                    _loc_3.sellvalue = this.shop[_loc_6].value;
                    this.toolArray.push(_loc_3);
                }
            }
            else
            {
                for (_loc_7 in this.shop)
                {
                    
                    if (this.shop[_loc_7].npcid == this._npcid && ModelProxy.getValue("data", "worldlevel") >= this.shop[_loc_7].minworldlv && ModelProxy.getValue("data", "worldlevel") <= this.shop[_loc_7].maxworldlv)
                    {
                        _loc_4 = this.shop[_loc_7].selltype;
                        _loc_3 = ItemObject.create(this.items[this.shop[_loc_7].itemid]);
                        _loc_3.sellvalue = this.shop[_loc_7].value;
                        this.toolArray.push(_loc_3);
                    }
                }
            }
            if (_loc_4 == 1)
            {
                _loc_8 = "suishen";
                this.xiuliBtn.visible = true;
            }
            else
            {
                this.xiuliBtn.visible = true;
                _loc_8 = "suishen";
                if (_loc_4 == 1)
                {
                    _loc_8 = "suishen";
                    this.xiuliBtn.visible = true;
                }
                else if (_loc_4 == 2)
                {
                    _loc_8 = "yaodian";
                    (this.parent as ShopUICtrl).titleLabel.text = "药店";
                }
                else if (_loc_4 == 3)
                {
                    _loc_8 = "wuqi";
                    (this.parent as ShopUICtrl).titleLabel.text = "武器店";
                }
                else if (_loc_4 == 4)
                {
                    _loc_8 = "hangju";
                    (this.parent as ShopUICtrl).titleLabel.text = "防具店";
                }
                else if (_loc_4 == 5)
                {
                    _loc_8 = "shoushi";
                    (this.parent as ShopUICtrl).titleLabel.text = "首饰店";
                }
                else if (_loc_4 == 6)
                {
                    _loc_8 = "shudian";
                    (this.parent as ShopUICtrl).titleLabel.text = "书店";
                }
                else if (_loc_4 == 7)
                {
                    _loc_8 = "zhahuo";
                    (this.parent as ShopUICtrl).titleLabel.text = "杂货店";
                }
            }
            _loc_2 = 0;
            while (_loc_2 < this.toolArray.length)
            {
                
                if (this.itemList.length <= _loc_2)
                {
                    break;
                }
                this.itemList[_loc_2].data = this.toolArray[_loc_2];
                _loc_2++;
            }
            return;
        }// end function

        private function onChuShou(event:MouseEvent) : void
        {
            ModelProxy.change("bag", "chushou", null);
            return;
        }// end function

        private function onXiuLi(event:MouseEvent) : void
        {
            PluginManager.instance.sendToServer("shop", CMDShop.XiuAll, 0);
            return;
        }// end function

    }
}
